package cn.xopencode.recordservice.dal.mysql.mapper.pdroom;

import cn.xopencode.mybatis.core.query.QueryWrapperX;
import cn.xopencode.recordservice.dal.mysql.dataobject.pdroom.PowerDistributionRoomDO;
import cn.xopencode.recordservice.service.pdroom.bo.PowerDistributionRoomBO;
import cn.xopencode.recordservice.service.pdroom.bo.PowerDistributionRoomPageBO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PowerDistributionRoomMapper extends BaseMapper<PowerDistributionRoomDO> {

    /**
     * 根据配电室名称模糊匹配
     * @param roomName
     * @return
     */
    default List<PowerDistributionRoomDO> selectLikeRoomName(String roomName){
        return selectList(new QueryWrapper<PowerDistributionRoomDO>().like("room_name",roomName));
    }

    default IPage<PowerDistributionRoomDO> selectPage(PowerDistributionRoomPageBO pageBO) {
        return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
                new QueryWrapperX<PowerDistributionRoomDO>()
                        .eqIfPresent("major", pageBO.getMajor())
                        .eqIfPresent("room_area", pageBO.getRoomArea())
                        .likeIfPresent("room_name", pageBO.getRoomName()));
    }

    default PowerDistributionRoomDO selectOneByParam(PowerDistributionRoomBO roomBO){
        return selectOne(new QueryWrapper<PowerDistributionRoomDO>()
                .eq("record_type", roomBO.getRecordType())
                .eq("num", roomBO.getNum())
                .eq("status", 1));
    }

    default List<PowerDistributionRoomDO> selectPdroomNameListByType(Integer recordType){
        return selectList(new QueryWrapper<PowerDistributionRoomDO>()
                .eq("record_type", recordType)
                .eq("status", 1));
    }
}
